<template>
  
</template>

<script>
import { AddUsers } from '../api/home'
export default {
  data () {
    return {
      showClo: false,
      dialogTableVisible: true,
      // 性别数据 - 1: 男， 2: 女
      radio: '1',
      uploadActionUrl: 'http://localhost:5000/HeadPortrait',
      // 注册表单
      registerForm: {
        NickName: "",
        Username: "",
        Password: "",
        checkpassword: "",
        phone: "",
        mailbox: "",
        Sex: " ",
        Age: " ",
        Remark: "用户"
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 7, message: "长度在 3 到7 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 12, message: "长度在 6 到 12 个字符", trigger: "blur" },
        ],
        checkpassword: [
          { required: true, message: "请确认密码", trigger: "blur" },
          { min: 6, max: 12, message: "长度在 6 到 12 个字符", trigger: "blur" },
        ],
        Email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          {
            type: 'email',
            message: '请输入正确的邮箱地址',
            trigger: ['blur', 'change'],
          },
        ]
      },
    };
  },

  methods: {
    // 取消注册
    cancel () {
      this.$router.push('/');
    },
    submitUpload () {
      console.log(123);
    },

    ExceededQuantity () {
      alert("抱歉，选中图片超出限制")
    },
    toInfo () {
      this.$router.push('userinfo')
    },
    // 注册
    RegisterOne: function () {
      console.log(this.registerForm);
      if (this.registerForm.Username != '' && this.registerForm.Password != '' && this.registerForm.Age != 0 &&
        this.registerForm.Sex != '' && this.registerForm.mailbox != '' && this.registerForm.phone != '') {
        this.registerForm.Sex = parseInt(this.registerForm.Sex)
        this.registerForm.phone = parseInt(this.registerForm.phone)
        if (this.registerForm.Password == this.registerForm.checkpassword) {
          AddUsers(this.registerForm).then((res) => {
            console.log(res.data.data);
            alert("注册成功")
            this.$router.push({ name: "Headpicture", params: { key: res.data.data.id } });
            this.dialogTableVisible = false;
          })
        }
        else {
          alert("请确认两次输入密码相同")
        }
      }
      else {
        alert("不能为空");
      }

    }
  }
};
</script>

<style scoped>
</style>